import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';


// 数据模型：存储用户信息
class UserInfoBean {
  final String userId;
  final String userName;

  // 构造函数（命名参数，清晰易读）
  UserInfoBean({
    required this.userId,
    required this.userName,
  });
}

class UserInfo extends StatelessWidget {
  final UserInfoBean userInfoBean;

   const UserInfo({super.key, required this.userInfoBean});


  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: "用户信息",
      theme: ThemeData(
        colorSchemeSeed: Colors.indigo,
        useMaterial3: true,
        visualDensity: VisualDensity.standard,
      ),
      // 传递参数给实际展示的页面
      home: UserInfoPage(userInfoBean: userInfoBean),
    );
  }
}

// 实际展示用户信息的页面（StatefulWidget，支持后续扩展状态）
class UserInfoPage extends StatefulWidget {
  final UserInfoBean userInfoBean;

  const UserInfoPage({
    super.key,
    required this.userInfoBean,
  });

  @override
  State<UserInfoPage> createState() => _UserInfoPageState();
}

class _UserInfoPageState extends State<UserInfoPage> {
  @override
  Widget build(BuildContext context) {
    // 通过 widget 访问父组件传递的参数
    final user = widget.userInfoBean;

    return Scaffold(
      appBar: AppBar(
        title: const Text("用户详情"),
        // 添加返回按钮（如果是独立页面，返回按钮会失效，可根据需求隐藏）
        automaticallyImplyLeading: true,
      ),
      body: SafeArea(
        child: SingleChildScrollView(
          padding: const EdgeInsets.all(20),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              // 展示用户ID
              Text(
                "用户ID：${user.userId}",
                style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w500),
              ),
              const SizedBox(height: 20),
              // 展示用户名
              Text(
                "用户名：${user.userName}",
                style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w500),
              ),
              const SizedBox(height: 20),
              Text(
                "其他信息：这是用户详情页示例",
                style: TextStyle(fontSize: 16, color: Colors.grey[600]),
              ),
            ],
          ),
        ),
      ),
    );
  }
}